package edu.gatech.asthma.activity;

import edu.gatech.asthma.R;
import edu.gatech.asthma.database.DBAdapter;
import edu.gatech.asthma.ui_support.HelpMenuHelper;
import edu.gatech.asthma.ui_support.ProfileCustomizer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Activity that allows user to enter breathing test results
 */
public class BreathingTestActivity extends Activity {

	int identifier = -1;
	DBAdapter database;
	ProfileCustomizer customizer;
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_breathing_test);
        
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
        	identifier = extras.getInt("ID");
        }
        database = new DBAdapter(this);
        database.open();
        customizer = new ProfileCustomizer(this,this.findViewById(android.R.id.content),database,identifier);
        customizer.setCustomizations();
    }

	/**
	 * Called when user clicks the submit button on this screen
	 * @param v The View (Button) that was clicked
	 */
	public void onSubmitClicked(View v) {
		//user did not enter reactance
		if (((EditText) findViewById(R.id.test_reactance)).getText().toString().equals("")) {
			Toast toast = Toast.makeText(this, getResources().getString(R.string.test_reactance_blank), Toast.LENGTH_LONG);
			toast.show();
		}
		//user did not enter reactance
		else if (((EditText) findViewById(R.id.test_resistance)).getText().toString().equals("")) {
			Toast toast = Toast.makeText(this, getResources().getString(R.string.test_resistance_blank), Toast.LENGTH_LONG);
			toast.show();
		}
		else {
			//TODO store in database
			Intent i = new Intent(BreathingTestActivity.this, HomeScreenActivity.class);
	    	i.putExtra("ID", identifier);
	    	BreathingTestActivity.this.startActivity(i);
		}
	}
	
	@Override
	public void onBackPressed() {
		//do not allow the user to press back on this page
	}
	
	/**
	 * User clicked the help button on this screen
	 * @param v ImageView clicked
	 */
	public void helpButtonClicked(View v) {
		HelpMenuHelper.displayHelpMessage(this);
	}
}